<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of StoreController
 *
 * @author WIN7
 */
class StoreController extends Controller{
    
    private $idSalePoint;
    private $viewData;
//    private $rows_item;
    private $modelCategory;
    private $modelItem;
    private $modelSalePoint;
//    private $mode

    public function init() {

        $this->modelItem = new ItemForm();
        
        $this->modelSalePoint = new SalePointForm();
        
        $this->modelCategory = new CategoryForm();
        
        // var row id sale point
//        $rows_salepoint = $this->modelSalePoint->getDatabase();
        if (isset($_GET['index']) && $_GET['index'] != NULL) {
            Yii::app()->session['idSalePoint'] = $_GET['index'];
        }

//        else
//            $this->idSalepoint = 1;    
    }

    public function actions() {
        
    }

    /**
     * This is the default 'index' action that is invoked
     * when an action is not explicitly requested by users.
     */
    public function actionIndex() {
        $this->layout = FALSE;                  
        
//        check idSalePoint, if null the store 1 is default
        if ($this->idSalePoint == null)
//            $this->idSalepoint = 1; // store 1 is default
            $this->idSalePoint = Yii::app()->session['idSalePoint'];

        $rows_category = $this->modelCategory->getCategory($this->idSalePoint);
        
        $rows_item = $this->modelItem->getItem($this->idSalePoint);
        
        $row_salepoint = $this->modelSalePoint->getSalePoint($this->idSalePoint);
        
        $this->viewData['categories'] = $rows_category; // 
        $this->viewData['items'] = $rows_item;
        $this->viewData['salepoint'] = $row_salepoint; //sale point only one row

        $this->render('index', $this->viewData);
    }
    public function actionItem() {
        $this->layout = FALSE;                  
        
//        $rows_category = $this->modelCategory->getCategory($this->idSalepoint);
        
        //        check idSalePoint
        if ($this->idSalePoint == null)
//            $this->idSalepoint = 1;
              $this->idSalePoint = Yii::app()->session['idSalePoint'];

        
        $rows_item = $this->modelItem->getItem($this->idSalePoint);
        
        $row_salepoint = $this->modelSalePoint->getSalePoint($this->idSalePoint);
        
//        $this->viewData['categories'] = $rows_category;
        $this->viewData['items'] = $rows_item;
        $this->viewData['salepoint'] = $row_salepoint; //sale point only one row

        $this->render('item', $this->viewData);
    }
}

?>
